<?php

class RegistrationController extends Zend_Controller_Action
{

    protected $_form = null;

    protected $_namespace = 'RegistrationController';

    protected $_session = null;

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    	$request = $this->getRequest();
    	$form    = new Application_Form_Register();
    	if ($this->getRequest()->isPost()) {
    		if ($form->isValid($request->getPost())) {
    			Zend_Loader::loadClass('Zend_Filter_StripTags');
    			$filter=new Zend_Filter_StripTags();
    			$mobile = $filter->filter($this->_request->getPost('mobile_tel'));
    			$password = $filter->filter($this->_request->getPost('password'));
    			$name = $filter->filter($this->_request->getPost('name'));
    			$email = $filter->filter($this->_request->getPost('email'));
    			$user = new Application_Model_User();

    			
    			if(!empty($mobile)){
    				$mapper = new Application_Model_UserMapper();
    				$hasMobile = $mapper->hasMobile($mobile);
    				if($hasMobile){
    					$this->view->msg = "Mobile Num already exists!";
    					$this->view->form = $form;
    					return;
    				}else{
    					$user->setMobileTel($mobile);
    					$user->setPassword($password);
    					$user->setName($name);
    					$user->setEmail($email);
    					
    					$mapper->save($user);
    					$this->_redirect('user/dump');
    					
    				}
    				
    				
    			}
    		}
    	}

    	$this->view->form = $form;
    	

    }

    public function finishAction()
    {
        // action body
    }


}





